import GameManager from "../Manager/GameManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class FailPanel extends cc.Component {
    public static Instance: FailPanel;

    @property(cc.Node)
    public Button_back: cc.Node = null;
    @property(cc.Node)
    public Button_restart: cc.Node = null;

    onLoad() {
        FailPanel.Instance = this;
    }

    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();
    }

    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }

    Refresh() {
    }

    AddListener() {
        this.Button_back.on(cc.Node.EventType.TOUCH_START, this.On_Button_back, this);
        this.Button_restart.on(cc.Node.EventType.TOUCH_START, this.On_Button_restart, this);
    }

    RemoveListener() {
        this.Button_back.off(cc.Node.EventType.TOUCH_START, this.On_Button_back, this);
        this.Button_restart.off(cc.Node.EventType.TOUCH_START, this.On_Button_restart, this);
    }

    On_Button_back() {
        this.ShowOff();
        GameManager.Instance.ExitGame();
    }

    On_Button_restart() {
        this.ShowOff();
        GameManager.Instance.ReStartGame();
    }
}